package sg.edu.nus.iss.vmcs.customer;

import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import sg.edu.nus.iss.vmcs.maintenance.DrinkDisplay;
import sg.edu.nus.iss.vmcs.maintenance.MaintenanceController;
import sg.edu.nus.iss.vmcs.system.MainController;
import sg.edu.nus.iss.vmcs.util.LabelledDisplay;
import sg.edu.nus.iss.vmcs.util.WarningDisplay;


public class CustomerPanel extends Dialog {

	private static final String TITLE = "Customer Panel";
	private CoinInputBox coinInputBox;	
	private WarningDisplay invalidCoin;
	private LabelledDisplay totalMoney;
	private DrinkSelectionBox drinkSelectionBox;
	private WarningDisplay noChange;
	private Button terminate;
	private LabelledDisplay collectCoin;
	private LabelledDisplay collectCan;
	
	private TransactionController tCtrl;
	
	public CustomerPanel(Frame fr, TransactionController tc) {
		super(fr, TITLE, false);
		tCtrl = tc;
		
		Label lb = new Label("VIMTO Soft Drink Dispenser");
		lb.setFont(new Font("Helvetica", Font.BOLD, 24));
		Panel tp=new Panel();
		tp.add(lb);
		
		coinInputBox=new CoinInputBox(tc.getCoinReceiver());		
				
		invalidCoin=new WarningDisplay("Invalid Coin");
		totalMoney=new LabelledDisplay("Total Money Inserted:",10,LabelledDisplay.FLOW);
		totalMoney.setEditable(false);
				
		Panel coinInputPanel=new Panel(new GridLayout(0,1));
		coinInputPanel.add(coinInputBox);
		coinInputPanel.add(invalidCoin);
		coinInputPanel.add(totalMoney);

		Panel top=new Panel(new BorderLayout());
		top.add("North",tp);
		top.add("South",coinInputPanel);
		
		drinkSelectionBox=new DrinkSelectionBox(tCtrl);
		
		noChange=new WarningDisplay("No/Less Change  Available");
		Panel pnlNoChange=new Panel(new FlowLayout());
		pnlNoChange.add(noChange);
		
		terminate=new Button("Terminate and Return Cash");
		terminate.addActionListener(new TerminateButtonListenser(this.tCtrl));
		Panel pnlTerminate=new Panel(new FlowLayout());
		pnlTerminate.add(terminate);
		
		collectCoin=new LabelledDisplay("Collect Coins:", 5,LabelledDisplay.FLOW);
		collectCoin.setEditable(false);
		Panel pnlCollectCoin=new Panel(new FlowLayout());
		pnlCollectCoin.add(collectCoin);
		
		collectCan=new LabelledDisplay("Collect Can Here:", 5,LabelledDisplay.FLOW);
		collectCan.setEditable(false);
		Panel pnlCollectCan=new Panel(new FlowLayout());
		pnlCollectCan.add(collectCan);
		
		
		Panel south=new Panel(new GridLayout(0,1));
//		south.add(pnlNoChange);
//		south.add(pnlTerminate);
//		south.add(pnlCollectCoin);
//		south.add(pnlCollectCan);
		south.add(noChange);
		south.add(pnlTerminate);
		south.add(collectCoin);
		south.add(collectCan);
		
		Panel center=new Panel(new BorderLayout());
		center.add("North", drinkSelectionBox);
		center.add("Center",south);
		
		
		
		this.setLayout(new BorderLayout());
		this.add("North", top);
		this.add("South", center);	
		pack();
		
		
		 addWindowListener(new WindowAdapter() {
			    public void windowClosing(WindowEvent e) {
			    	tCtrl.closeDown();
		                dispose();
		            }
			});
		
	}

	public void display() {
		System.out.println("CustomerPanel: before display");
		this.setVisible(true);
		System.out.println("CustomerPanel: after display");
	}

	public void closeDown() {
		dispose();
	}
	
	//to modify
	public void setActive(char component,Boolean st){
		coinInputBox.setActive(st);	
		invalidCoin.setEnabled(st);
		totalMoney.setActive(st);
		drinkSelectionBox.setActive(st);
		noChange.setEnabled(st);
		terminate.setEnabled(st);
		collectCoin.setActive(st);
		collectCan.setActive(st);
	}
	
	//Extra Method
	public DrinkSelectionBox getDrinkSelectionBox(){
		return this.drinkSelectionBox;
	}
	
	//Extra Method
	public CoinInputBox getCoinInputBox(){
		return this.coinInputBox;
	}
	
	//Extra Method
	/*
	 * Refund/Change Display
	 */
	public LabelledDisplay getCollectCoinDisplay(){
		return this.collectCoin;
	}
	
	//Extra Method
	/*
	 * Can Collection Box Display
	 */
	public LabelledDisplay getCollectCanDisplay(){
		return this.collectCan;
	}
	
	//Extra Method
	/*
	 * TotalMoneyInserted Display
	 */
	public LabelledDisplay getTotalMoneyDisplay(){
		return this.totalMoney;
	}
	
	//Extra Method
	/*
	 * Invalid Coin Display
	 */
	public WarningDisplay getInvalidCoinDisplay(){
		return this.invalidCoin;
	}
	
	//Extra Method
	/*
	 * No Change Available Display
	 */
	public WarningDisplay getNoChangeDisplay(){
		return this.noChange;
	}

}
